package apka.SMSBillet.Activities;

import android.app.Activity;
import android.app.PendingIntent;
import android.app.ProgressDialog;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.ProgressBar;
import android.widget.TextView;
import apka.SMSBillet.R;
import apka.SMSBillet.SMSManager;
import apka.SMSBillet.R.id;
import apka.SMSBillet.R.layout;


public class ConfirmTicket extends Activity{
	private Button btnConfirm = null;
	private Button btnRedo = null;
	private String sMessage = null;
	private TextView tVMessage = null;
	private LinearLayout buttonLL = null;

	@Override
	public void onCreate(Bundle savedInstanceState) {
	    super.onCreate(savedInstanceState);
	    setContentView(R.layout.confirm_ticket);
	    initiateViews();
	    loadLastActivity();
	    setListeners();
	}

	private void setListeners() {
		btnConfirm.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				sendSMS("1271","JA");
				ProgressDialog dialog = ProgressDialog.show(ConfirmTicket.this, "Afventer svar fra NT",
						"Vent venligst indtil svar er modtaget", true);
				
			}
		});
		
		btnRedo.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				Intent startIntent = new Intent(getApplicationContext(), FindTravel.class);
				startActivity(startIntent);			
			}
		});
	}
	

	
	private void sendSMS(String phoneNumber, String message) {
		PendingIntent pi = PendingIntent.getActivity(this, 0, new Intent(this,
				ConfirmTicket.class), 0);
//		SmsManager sms = SmsManager.getDefault();
//		sms.sendTextMessage(phoneNumber, null, message, pi, null);
		
		SMSManager.getInstance();
		SMSManager.sendSMS(phoneNumber, message, null);
	}

	private void loadLastActivity() {
		Intent callingIntent = getIntent();
		sMessage = callingIntent.getStringExtra("Message");
		tVMessage.setText(sMessage);
	}

	public void initiateViews(){
		tVMessage = (TextView) findViewById(R.id.confirm_message);
		btnConfirm = (Button) findViewById(R.id.btn_buy_travel);
		btnRedo = (Button) findViewById(R.id.btn_redo_travel);
		buttonLL = (LinearLayout) findViewById(R.id.ll_Confirm_btn);
	}
	
}
